'''
Created on 2011-9-24

@author: 123kangta
'''
from test import generator
import unittest

socket_server = generator.create_socket_server()

class InitWebSocketRequestTest(unittest.TestCase):
    def test_application_scope_variable(self):
        request1 = generator.create_request()
        request2 = generator.create_request()

        request1.app("hello", "request1")

        self.assertEqual("request1", request1.app("hello"))
        self.assertEqual("request1", request2.app("hello"))

        request2.app("hello", "request2")
        self.assertEqual("request2", request1.app("hello"))

        target = [1, 2]
        request1.app("all", target)
        self.assertEqual(target, request1.app("all"))
        self.assertEqual(target, request2.app("all"))


    def test_application_defalut_value(self):
        init_message = "there is not"
        request1 = generator.create_request()
        request2 = generator.create_request()

        request1.app("say", default=init_message)

        defaultValue = set()
        request1.app("sameValue", default=defaultValue)
        defaultValue.add("aaa")

        self.assertEqual(request2.app("say"), init_message)
        self.assertTrue("aaa" in request2.app("sameValue"))

        self.assertTrue("aaa" in request2.app("sameValue", default=defaultValue))

        other_default_value = set()
        self.assertEqual(id(other_default_value), id(request1.app("sameValue1", default=other_default_value)))


